﻿Public Class GlyphMetricsCanvas
    Inherits FrameworkElement

    Private Shared FillBrush As Brush = New SolidColorBrush(Color.FromArgb(32, 0, 0, 0))

    Shared Sub New()
        FillBrush.Freeze()
    End Sub

    Public Shared ReadOnly ZoomProperty As DependencyProperty = _
        DependencyProperty.Register( _
            "Zoom", GetType(Double), GetType(GlyphMetricsCanvas), _
            New FrameworkPropertyMetadata(1.0#, FrameworkPropertyMetadataOptions.AffectsRender))

    Public Property Zoom As Double
        Get
            Return CType(GetValue(ZoomProperty), Double)
        End Get
        Set(ByVal value As Double)
            SetValue(ZoomProperty, value)
        End Set
    End Property

    Protected Overrides Sub OnRender(dc As DrawingContext)
        MyBase.OnRender(dc)

        dc.DrawRectangle(FillBrush, Nothing, New Rect(0, 0, ActualWidth, GlyphMetrics.BorderOverflow))
        dc.DrawRectangle(FillBrush, Nothing, New Rect(0, GlyphMetrics.BorderOverflow + GlyphMetrics.Height, ActualWidth, GlyphMetrics.BorderOverflow))
        dc.DrawRectangle(FillBrush, Nothing, New Rect(0, 0, GlyphMetrics.BorderOverflow, ActualHeight))
        dc.DrawRectangle(FillBrush, Nothing, New Rect(ActualWidth - GlyphMetrics.BorderOverflow, 0, GlyphMetrics.BorderOverflow, ActualHeight))

        Dim halfLineWidth = 1 / Zoom
        dc.DrawRectangle(FillBrush, Nothing, New Rect(ActualWidth / 2 - halfLineWidth, 0, halfLineWidth * 2, ActualHeight))
        dc.DrawRectangle(FillBrush, Nothing, New Rect(0, ActualHeight / 2 - halfLineWidth, ActualWidth, halfLineWidth * 2))
    End Sub

End Class
